from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains

d = webdriver.Chrome()
d.get('http://192.168.0.125:9009/')
js = "window.scrollTo(0,1000);"
d.execute_script(js)
dl = d.find_element(By.LINK_TEXT, '登录')
dl.click()
username = d.find_element(By.CSS_SELECTOR, '[name="log"]')
username.send_keys('admin')
password = d.find_element(By.CSS_SELECTOR, '[name="pwd"]')
password.send_keys('admin123')
time.sleep(2)
deng = d.find_element(By.CSS_SELECTOR, '[name="wp-submit"]')
deng.click()
a = d.find_element(By.CSS_SELECTOR, '[id="menu-users"] a [class="wp-menu-name"]')
ActionChains(d).move_to_element(a).perform()
b = d.find_element(By.LINK_TEXT, '添加用户')
b.click()
# 针对 select 标签的下拉框，有单独的一套方案
# 1、先定位到下拉框
opts = d.find_element(By.CSS_SELECTOR, '[name="role"]')
# 导入select模块
# Select(下拉框定位).select_by_index() # 根据下标选择
# Select(下拉框定位).select_by_value() # 根据选项的 value 属性值 选择
# Select(下拉框定位).select_by_visible_text() # 根据选项的文本信息选择
Select(opts).select_by_index(3) # 根据下标选择
time.sleep(1)
Select(opts).select_by_value('editor') # 根据选项的 value 属性值 选择
time.sleep(1)
Select(opts).select_by_visible_text('订阅者') # 根据选项的文本信息选择
time.sleep(1)